package com.cloud.flowable.controller;

import com.alibaba.fastjson.JSONObject;
import com.cloud.common.domain.Result;
import com.cloud.controller.BaseController;
import com.cloud.flowable.entity.WfFormTest;
import com.cloud.flowable.service.IWfFormTestService;
import com.cloud.security.aop.RequestPermissions;
import com.cloud.utils.StringUtils;
import com.cloud.utils.ToolUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 流程表单测试表
 *
 * @author yzj
 * @since 2024-02-26
 */
@Tag(name = "流程表单测试表")
@RestController
@RequestMapping("/flowable/formTest")
public class WfFormTestController extends BaseController {

    @Autowired
    private IWfFormTestService wfFormTestService;

    @Operation(summary = "流程表单测试表分页")
    @RequestPermissions("flowable:formTest:list")
    @GetMapping("/list")
    public Result list(WfFormTest wfFormTest) {
        startPage();
        List<WfFormTest> wfFormTestList = wfFormTestService.getWfFormTestList(wfFormTest);
        return getDataTable(wfFormTestList);
    }

    @Operation(summary = "新增流程表单测试表")
    @RequestPermissions("flowable:formTest:add")
    @PostMapping("/insert")
    public Result insert(@RequestBody WfFormTest wfFormTest) {
        if (StringUtils.isEmpty(wfFormTest.getNodeKey())) {
            return Result.error("流程开始节点KEY不能为空");
        }
        if (StringUtils.isEmpty(wfFormTest.getProcessKey())) {
            return Result.error("流程定义KEY不能为空");
        }
        return toResult(wfFormTestService.saveWfFormTest(wfFormTest));
    }

    @Operation(summary = "修改流程表单测试表")
    @PostMapping("/update")
    public Result update(@RequestBody JSONObject param) {
        if (StringUtils.isNull(param)) {
            return Result.error("请求参数不能为空");
        }
        return toResult(wfFormTestService.editWfFormTest(param));
    }

    @Operation(summary = "删除流程表单测试表")
    @RequestPermissions("flowable:formTest:remove")
    @PostMapping("/remove")
    public Result remove(String ids) {
        List<Long> list = ToolUtils.setIdsToList(ids);
        return toResult(wfFormTestService.removeIds(list));
    }

}
